export default {
    namespaced: true,
    state: {
      list: [
        { id: 100, name: "吃饭", isDone: true },
        { id: 101, name: "睡觉", isDone: false },
        { id: 102, name: "打豆豆", isDone: true },
      ]
    },
    mutations: {
      setIsDone (state, id) {
        state.list.forEach(obj => {
          if (obj.id === id) {
            obj.isDone = !obj.isDone
          }
        })
      },
  
      setList (state, list) {
        state.list = list
      },
  
      delList (state, id) {
        state.list = state.list.filter((obj) => obj.id !== id)
      },
  
      addList (state, task) {
        state.list.push({
          id: state.list.at(-1)?.id + 1 || 100,
          name: task,
          isDone: false
        })
      },
  
      allList (state, all) {
        state.list.forEach(obj => obj.isDone = all)
      },
  
      clearList (state) {
        state.list = state.list.filter(obj => !obj.isDone)
      }
    }
  }